<section class="content-header">
  <ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
    <li><a href="#">权限管理</a></li>
    <li class="active">用户管理</li>
  </ol>
</section>
<!-- Main content 搜索 新增 删除-->
<section class="content">
  <div class="jax-box">
    <form id="formSearch" class="form-horizontal form-search">
      <div class="form-group">
        <div class="col-md-4 col-sm-6">
          <label class="control-label  col-xs-4" for="svrType">服务类型:</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" id="svrType">
          </div>
        </div>
        <div class="col-md-4 col-sm-6">
          <label class="control-label  col-xs-4" for="serCreateName">创建人:</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" id="serCreateName">
          </div>
        </div>
        <div class="col-md-3 col-sm-6">
          <label class="control-label  col-xs-4" for="serStatus">服务状态:</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" id="serStatus">
          </div>
        </div>
        <!--                <shiro:hasPermission name="user:list">-->
        <div class="col-md-1 col-sm-6 " style="text-align:left;">
          <button type="button" id="btn_query" class="btn btn-info">查询</button>
        </div>
        </shiro:hasPermission>
      </div>
    </form>
  </div>
  <div class="jax-box jax-box-table">
    <div id="toolbar" class="btn-group">
      <shiro:hasPermission name="user:add">
        <button id="btn_add" type="button" class="btn btn-primary" data-toggle="modal" data-target="#userModal">
          <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增服务
        </button>
      </shiro:hasPermission>
      <shiro:hasPermission name="user:batchDelete">
        <button id="btn_batch_delete" type="button" class="btn btn-danger">
          <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
        </button>
      </shiro:hasPermission>
    </div>
    <table id="table"></table>
  </div>
</section>
<!-- 用户新增模态框 -->
<div id="userModal" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title">新增用户</h4>
      </div>
      <div class="modal-body">
        <form class="form-horizontal" id="userForm">
          <div class="box-body">
            <div class="form-group">
              <label class="col-sm-3 control-label">服务类型 <span style="color: red">*</span>:</label>
              <div class="col-sm-8">
                <input name="serType" class="form-control" min="3" require="必填项" placeholder="">
              </div>
            </div>
            <!--                        <div class="form-group">-->
            <!--                            <label class="col-sm-3 control-label">服务状态 <span style="color: red">*</span>:</label>-->
            <!--                            <div class="col-sm-8">-->
            <!--                                <input name="serStatus" type="text" class="form-control" require="必填项" placeholder="'1'为合作，'0'为失效">-->
            <!--                            </div>-->
            <!--                        </div>-->
            <div class="form-group">
              <label class="col-sm-3 control-label">服务创建人编号 <span style="color: red">*</span>:</label>
              <div class="col-sm-8">
                <input name="serCreateId" type="text" class="form-control" require="必填项" placeholder="">
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label">服务创建人姓名 </label>
              <div class="col-sm-8">
                <input name="serCreateName" class="form-control" placeholder="">
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label">概要 </label>

              <div class="col-sm-8">
                <input name="serTitle" class="form-control" placeholder="">
              </div>
            </div>
            <!--                        <div class="form-group">-->
            <!--                            <label class="col-sm-3 control-label">性别 :</label>-->
            <!--                            <div class="col-sm-8">-->
            <!--                                <select name="sex" class="form-control">-->
            <!--                                    <option value="0">请选择</option>-->
            <!--                                    <option value="1">男</option>-->
            <!--                                    <option value="2">女</option>-->
            <!--                                </select>-->
            <!--                            </div>-->
            <!--                        </div>-->
            <!--                        <div class="form-group">-->
            <!--                            <label class="col-sm-3 control-label">年龄 :</label>-->
            <!--                            <div class="col-sm-8">-->
            <!--                                <input name="age" class="form-control" placeholder="">-->
            <!--                            </div>-->
            <!--                        </div>-->
          </div>
          <div class="box-footer">
            <div class="pull-right">
              <button type="button" id="saveUser" class="btn btn-info">确定</button>
              <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<script>
  var columns = [
    {checkbox: true},
    {
      field: 'serType',
      title: '服务类型',
      align: "center"
    }, {
      field: 'serCreateName',
      title: '创建人姓名',
      align: "center",
    }, {
      field: 'serCreateDate',
      title: '创建时间',
      align: "center",
    }, {
      field: 'serTitle',
      title: '服务概要',
      align: "center",
    }, {
      field: 'serStatus',
      title: '服务状态',
      align: "center",
      formatter: function (value, row, index) {
        return row.serStatus == '1' ? "合作中" : "失效";
      }
    }, {
      field: 'operation',
      title: '操作',
      align: "center",
      formatter: function (value, row, index) {
        var assign = true ? '<a class="table-btn table-btn-info"  href="javascript:void(1)" onclick="assignPermsList(' + row.serId + ')">服务进展</a>' : '';
        var create = true ? '<a class="table-btn table-btn-info"  href="javascript:void(1)" onclick="assignPermsList(' + row.serId + ')">新建服务</a>' : '';
        return assign+create;
      }
    }];
  var options = {
    id: "#table",
    url: '/serType/list',
    columns: columns,
    toolbar: '#toolbar',
    showRefresh: true,
    queryParams: queryParams
  }
  Core.initTable(options);

  /*查询用户参数*/
  function queryParams(params) {
    var temp = { //这里的键的名字和控制器的变量名必须一致，这边改动，控制器也需要改成一样的
      limit: params.limit, //页面大小
      offset: params.offset, //页码
      serType: $("#serType").val(),
      serCreateName: $("#serCreateName").val(),
      serStatus: $("#serStatus").val()
    };
    return temp;
  }

  $(function () {
    /*查询*/
    $("#btn_query").click(function () {
      Core.refreshTable("#table");
    });
    /*新增*/
    $("#btn_add").click(function () {
      Core.clearError("#userForm");
    });
  })
  /*批量删除*/
  $("#btn_batch_delete").click(function(){
    var checkedRows= Core.selectMutiData("#table");
    if(checkedRows){
      Core.confirm("确定删除选中的"+checkedRows.length+"条记录？",function () {
        userIdStr = "";
        $.each(checkedRows, function (i, item) {
          serId += (item.serId + ",");
        })
        serId = serId.substring(0, serId.length - 1);
        Core.postAjax("/serType/delete", {"serId": serId}, function (data) {
          if (data.status == 200) {
            Core.refreshTable("#table");
          }
          layer.msg(data.msg);
        }, "get")
      })
    }
  });
  /*保存服务*/
  $("#saveUser").click(function(){
    if(doValidForm(userForm)){
      Core.mask("#saveUser");
      Core.postAjax("/serType/add",$("#userForm").serialize(),function (data) {
        Core.unmask("#saveUser");
        if(data.status==200){
          $("#userModal").modal("hide");
          $("#userForm")[0].reset();
          Core.refreshTable("#table")
        }
        layer.msg(data.msg);
      })
    };
  });
</script>